package com.example.building_material_mannager.service.impl;

import com.example.building_material_mannager.entity.Payment;
import com.example.building_material_mannager.entity.PurchaseTable;
import com.example.building_material_mannager.mapper.PaymentMapper;
import com.example.building_material_mannager.mapper.PurchaseTableMapper;
import com.example.building_material_mannager.service.PurchaseTableService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;
//采购
@Service
public class PurchaseTableServiceImpl implements PurchaseTableService {
    @Resource
    PurchaseTableMapper  purchaseTableMapper;
    @Resource
    PaymentMapper paymentMapper;
    @Override
    public List<PurchaseTable> select(PurchaseTable PurchaseTable) {
        List<PurchaseTable> purchaseTables=purchaseTableMapper.select(PurchaseTable);
        return purchaseTables;
    }

    @Override
    public PurchaseTable selectByOrder(String pordernumber) {
        PurchaseTable purchaseTable=purchaseTableMapper.selectByOrder(pordernumber);
        return purchaseTable;
    }

    @Override
    public boolean add(PurchaseTable purchaseTable) {
        boolean addPurchaseTable=purchaseTableMapper.add(purchaseTable);
        Payment payment =new Payment(null,"纸质","未支付",null,purchaseTable.getPordernumber());
        boolean addPayment=paymentMapper.addPayment(payment);
        if(addPurchaseTable && addPayment){
            return true;
        }
        return false;
    }

    @Override
    public boolean delete(String pordernumber) {
        boolean re=purchaseTableMapper.delete(pordernumber);
        return re;
    }

    @Override
    public boolean update(PurchaseTable purchaseTable) {
        boolean re=purchaseTableMapper.update(purchaseTable);
        return re;
    }
}
